package com.wn.order.controller;

import com.alibaba.druid.sql.visitor.functions.If;
import com.github.pagehelper.PageInfo;
import com.wn.common.entity.Const;
import com.wn.common.entity.MyParam;
import com.wn.common.entity.MyRsp;
import com.wn.common.pojo.Orders;
import com.wn.order.common.DataGridResponse;
import com.wn.order.feign.UserFeign;
import com.wn.order.service.OrderService;
import com.wn.order.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;

/**
 * @BelongsProject: shared_parking
 * @BelongsPackage: com.wn.order.controller
 * @Author: 段彪
 * @CreateTime: 2020-06-11 12:16
 * @Description: 表现层
 */
@RestController
@Slf4j
@Api(description = "orderApi接口")
public class OrderController {


    @Autowired
    OrderService orderService;

    @Autowired
    UserFeign userFeign;


    @GetMapping("getAll")
    @ApiOperation("查询所有订单")
    public MyRsp getAll(){
        List<Orders> all = orderService.getAll();
        return MyRsp.success(all);
    }
    //生成所有订单
    @PostMapping("addOrders")
    @ApiOperation("生成订单")
    public MyRsp addOrders(@RequestBody GenerateOrdersVo orders){
        System.out.println(orders);
        MyRsp myRsp = orderService.addOrders(orders);
        return myRsp;
    }
    @PostMapping("deleteOrdersById")
    @ApiOperation("逻辑删除")
    public MyRsp deleteOrdersById(@RequestBody Orders orders){
        String oId = orders.getOId();
        MyRsp myRsp = orderService.deleteOrdersById(oId);
        return myRsp;
    }

    @PostMapping("pagingQuery")
    @ApiOperation("分页查询")
    public MyRsp pagingQuery(@RequestBody MyParam<Orders> myParam){
        PageInfo<Orders> ordersPageInfo = orderService.pagingQuery(myParam);
        return MyRsp.success(ordersPageInfo);
    }
    @PostMapping("queryOrder")
    @ApiOperation("订单查询")
    public PropertyLessorVo queryOrder(){

        return null;
    }
    @PostMapping("getAllOrder")
    @ApiOperation("平台方分页订单查询和用户模糊查询")
    public DataGridResponse getAllOrder(Integer page,Integer rows, String username){
        DataGridResponse allOrder = orderService.getAllOrder(page,rows,username);
        return allOrder;
    }
    @PostMapping("getPropertyOrder")
    @ApiOperation("物业方分页订单查询和用户模糊查询")
    public DataGridResponse getPropertyOrder(Integer page,Integer rows, String username,@CookieValue(value = "token",defaultValue = "---") String token){
        DataGridResponse lessonOrder = orderService.getPropertyOrder(page, rows, username,token);
        return lessonOrder;
    }
    @PostMapping("getLessonOrder")
    @ApiOperation("出租方分页订单查询和用户模糊查询")
    public DataGridResponse getLessonOrder(Integer page,Integer rows, String username,@CookieValue(value = "token",defaultValue = "---") String token){
        DataGridResponse lessonOrder = orderService.getLessonOrder(page, rows, username,token);
        return lessonOrder;
    }

    @PostMapping("SettlementMoney")
    @ApiOperation("普通结算")
    public MyRsp SettlementMoney(@RequestBody Integer hour){
        BigDecimal bigDecimal = orderService.SettlementMoney(hour);
        return MyRsp.success1(Const.Status.STATUS_SUCCESS,"计算结果"+bigDecimal);
    }

    @PostMapping("viewEarnings")
    @ApiOperation("分页查询收益&&模糊查询")
    public DataGridResponse viewEarnings(Integer page,Integer rows,String name){
        DataGridResponse dataGridResponse = orderService.ViewEarnings(page, rows, name);
        return dataGridResponse;
    }
    @PostMapping("getAllPercentage")
    @ApiOperation("提成查询收益&&模糊查询")
    public DataGridResponse getAllPercentage(Integer page,Integer rows,String name){
        DataGridResponse allPercentage = orderService.getAllPercentage(page, rows, name);
        return allPercentage;
    }

    @PostMapping("updatePercentage")
    @ApiOperation("修改提成")
    public MyRsp updatePercentage(String tcId,String commission){
        MyRsp myRsp = orderService.updatePercentage(tcId, commission);
        return myRsp;
    }
    //获取订单用户名
    @PostMapping("getUserInfo")
    @ApiOperation("获取订单用户名")
    public MyRsp getUserInfo(@CookieValue(value = "token",defaultValue = "---") String token){
        MyRsp userInfo = userFeign.getUserInfo(token);
        return userInfo;
    }

    @PostMapping("getCarportVo")
    @ApiOperation("查询车辆信息")
    public MyRsp getCarportVo(@RequestBody CarPortAreaVillageVo carPortAreaVillageVo) {
        MyRsp carportVo = orderService.getCarportVo(carPortAreaVillageVo.getCpId());
        return carportVo; }


    @PostMapping("Pay")
    @ApiOperation("支付宝支付")
    public MyRsp Pay(@RequestBody MyParam<ZfbVo> myParam){
        MyRsp pay = orderService.Pay(myParam.getT().getOId());return pay; }

    @RequestMapping("aliPayCallback")
    @ApiOperation("支付宝回调")
    public String aliPayCallback(HttpServletRequest request){
       return orderService.aliPayCallback(request);
    }
    
    @ApiOperation(value = "支付宝订单查询")
    @RequestMapping("queryAliPayOrderStatus")
    public MyRsp queryAliPayOrderStatus(@RequestBody MyParam<Orders> myParam){
        if (myParam.getT().getOId()!=null){
            return orderService.queryAliPayOrderStatus(myParam); }else{ }return null; }

    @ApiOperation(value = "我的订单")
    @PostMapping("myOrders")
    public MyRsp myOrders(@RequestBody MyParam<MyOrderVo> myParam) {
        System.out.println(myParam);
        MyRsp myRsp=orderService.myOrders(myParam);
            return myRsp;
    }
    @ApiOperation(value = "物业方")
    @PostMapping("PropertyCommission")
    public DataGridResponse PropertyCommission(Integer page,Integer rows, String username,@CookieValue(value = "token",defaultValue = "---") String token){
        DataGridResponse dataGridResponse = orderService.PropertyCommission(page, rows, username, token);
        return dataGridResponse;
    }
    @ApiOperation(value = "平台方")
    @PostMapping("LessorCommission")
    public DataGridResponse LessorCommission(Integer page,Integer rows, String username,@CookieValue(value = "token",defaultValue = "---") String token){
        DataGridResponse dataGridResponse = orderService.LessorCommission(page, rows, username, token);
        return dataGridResponse;
    }
}
